package com.yanqu.road.entity.activity.daomu;

import java.math.BigDecimal;

public class DaoMuAttribute {

    //属性类型 1：生命，2：攻击，3：防御，4：速度, 5：暴击率，6：暴击伤害，7：伤害减免率，8：回血/s
    private int id;

    //值
    private BigDecimal value;

    //最大属性值
    private BigDecimal maxValue = BigDecimal.valueOf(99999999);

    //千分比加成
    private long addRate = 0;

    //固定值加成
    private long addValue = 0;

    //是否处理最大值
    private boolean maxFlag = true;

    public DaoMuAttribute() {

    }

    public DaoMuAttribute(int id, BigDecimal value, BigDecimal maxValue) {
        this.id = id;
        this.value = value;
        this.maxValue = maxValue;
    }

    public DaoMuAttribute(int id, BigDecimal value) {
        this.id = id;
        this.value = value;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public BigDecimal getValue() {
        if (this.maxFlag && this.value.compareTo(this.maxValue) > 0) {
            return this.maxValue;
        }
        return value;
    }

    public void setValue(BigDecimal value) {
        this.value = value;
    }

    public BigDecimal getMaxValue() {
        return maxValue;
    }

    public void addValue(long addValue) {
        this.value = this.value.add(BigDecimal.valueOf(addValue));
    }

    public void reValue(BigDecimal reValue) {
        this.value = this.value.subtract(reValue);
    }

    public long getAddRate() {
        return addRate;
    }

    public long getAddValue() {
        return addValue;
    }

    public void addAddRate(long addRate) {
        this.addRate += addRate;
    }

    public void addAddValue(long addValue) {
        this.addValue += addValue;
    }

    /**
     * 增加比例（千分比）
     */
    private void doAddRate() {
        BigDecimal rateBig = BigDecimal.valueOf(this.addRate + 1000).divide(BigDecimal.valueOf(1000));
        this.value = this.value.multiply(rateBig) ;
        this.addRate = 0;
    }


    /**
     * 增加固定值
     */
    private void doAddValue() {
        this.value = this.value.add(BigDecimal.valueOf(this.addValue));
        this.addValue = 0;
    }

    /**
     * 操作属性增加
     */
    public void doAdd() {
        //增加千分比
        this.doAddRate();
        //增加固定值
        this.doAddValue();
    }
}
